package com.hkts.management.upload.upload.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.management.upload.upload.entity.HktsFileRecord;
import com.hkts.management.upload.upload.mapper.HktsFileRecordMapper;
import com.hkts.management.upload.upload.service.IHktsFileRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yck
 * @since 2021-07-12
 */
@Service
@Transactional
public class HktsFileRecordServiceImpl extends ServiceImpl<HktsFileRecordMapper, HktsFileRecord> implements IHktsFileRecordService {


@Autowired
private HktsFileRecordMapper hktsFileRecordMapper;

@Override
public IPage<HktsFileRecord> selectPage(Page<HktsFileRecord> page, HktsFileRecord hktsFileRecord){
        QueryWrapper<HktsFileRecord> query = Wrappers.query();
        QueryWrapper<HktsFileRecord> entityWrapper = getEntityWrapper(query, hktsFileRecord);
        return hktsFileRecordMapper.selectPage(page, entityWrapper);
        }




@Override
public List<HktsFileRecord> selectList(HktsFileRecord hktsFileRecord){
        QueryWrapper<HktsFileRecord> query = Wrappers.query();
        QueryWrapper<HktsFileRecord> entityWrapper = getEntityWrapper(query, hktsFileRecord);
        return hktsFileRecordMapper.selectList(entityWrapper);
        }

/**
 *  公共查询条件
 * @param entityWrapper
 * @return
 */
public QueryWrapper<HktsFileRecord> getEntityWrapper(QueryWrapper<HktsFileRecord> entityWrapper,HktsFileRecord hktsFileRecord){
        //条件拼接
                if(StringUtils.isNotBlank(hktsFileRecord.getFileUrl())){
                entityWrapper.like(HktsFileRecord.FILE_URL,hktsFileRecord.getFileUrl());
                }
                if(StringUtils.isNotBlank(hktsFileRecord.getFileKey())){
                entityWrapper.like(HktsFileRecord.FILE_KEY,hktsFileRecord.getFileKey());
                }
                /*if(StringUtils.isNotBlank(hktsFileRecord.getCreateTime())){
                entityWrapper.like(HktsFileRecord.CREATE_TIME,hktsFileRecord.getCreateTime());
                }*/
        return entityWrapper;
        }
        }
